home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_10.lha
/
5_10
/
5_10a1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
51 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ look up a name within a symbol table
include <table.h>
include <string.h>
include <error.h>
ame *table::look(char *p, int ins)
// hash the name
int ii = 0;
char *pp = p;
while (*pp)
ii = (ii << 1) ^ *pp++;
if (ii < 0)
ii = -ii;
ii %= size;
// run down that list, looking for the name
for (name *n = tbl[ii]; n; n = n->next)
if (strcmp(p, n->string) == 0)
return n;
// the name was not found
switch (ins)
{
case 0:
error("name not found");
return 0;
case 2:
return 0;
case 1:
name *nn = new name(p);
nn->next = tbl[ii];
tbl[ii] = nn;
return nn;
default:
error("unknown ins value for table::look()");
return 0;
}